<script setup>
import { ref, onMounted } from 'vue'
import { getDriverPageAPI } from '@/services/driver'
import { getBusinessHallTreeAPI } from '@/services/businessHall'
import DriVer from '@/views/Employee/Driver/components/DriVer.vue'
import PanelTable from '@/views/Employee/Driver/components/PanelTable.vue'
import DetailDrawer from './components/DetailDrawer.vue'
//
const isLoading = ref(false)
const dataSource = ref([])
const total = ref(0)
const params = ref({
  page: 1,
  pageSize: 10,
})
console.log(params.value)

// 获取机构类型数据 - 下拉框
const truckTypes = ref([])
const isLoadingTruckTypes = ref(false)
const getTruckTypeData = async () => {
  isLoadingTruckTypes.value = true
  const res = await getBusinessHallTreeAPI()
  isLoadingTruckTypes.value = false
  truckTypes.value = res.data
}
onMounted(() => {
  // 获取车辆类型数据 - 下拉框
  getTruckTypeData()
  getData()
  console.log(getData(), 1)
})

// 获取数据
const getData = async () => {
  // 表格加载状态
  // isLoading.value = true
  // 传递参数
  const res = await getDriverPageAPI(params.value)
  console.log(res, 0)
  // 关闭表格加载状态
  // isLoading.value = false
  // 保存列表数据，用于表格展示
  dataSource.value = res.data.items
  // 保存分页总数
  total.value = Number(res.data.counts)
}
const ok = () => {
  getData()
}
// // 新增编辑车型
// const isOpenModal = ref(false)
// // 编辑车型id
// const editId = ref('')
// // 打开弹出层
// const onOpenModal = (id) => {
//   // 打开弹出层
//   isOpenModal.value = true
//   // 保存编辑车型id
//   editId.value = id ? id : undefined
// }
</script>

<template>
  <a-space direction="vertical" style="width: 100%">
    <a-card :bodyStyle="{ paddingBottom: 0 }">
      <!-- 表单部分 -->
      <DriVer
        v-model:page="params.page"
        v-model:pageSize="params.pageSize"
        @init="getData"
        @finish="getData"
        @reset="getData"
      />
    </a-card>
    <a-card>
      <!-- 新增按钮 -->
      <!-- <a-button type="primary" @click="onOpenModal()" style="margin-bottom: 20px">
        新增车型
      </a-button> -->
      <!-- 弹出层 新增/编辑 -->
      <!-- <ModalForm v-model:open="isOpenModal" :id="editId" @ok="getData()" /> -->
      <!-- 表格部分 -->
      <PanelTable
        :dataSource="dataSource"
        :loading="isLoading"
        :total="total"
        v-model:page="params.page"
        v-model:pageSize="params.pageSize"
        @change="getData"
        @edit="onOpenModal($event)"
        @ok="ok"
      />
    </a-card>
  </a-space>
  <DetailDrawer />
</template>
